#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

int n, m;
int tr[N][26], fail[N], cnt[N], deg[N], tot;
vector<int> a[N];
int newnode() { return ++tot; }
void insert(string s, int i) {
  int p = 0;
  for (char c : s) {
    int ch = c - 'a';
    if (!tr[p][ch]) tr[p][ch] = newnode();
    p = tr[p][ch];
  }
  a[p].push_back(i);
}
void build_ac() {
  queue<int> q;
  rep(i, 0, 25) if (tr[0][i]) q.push(tr[0][i]);
  while (q.size()) {
    int p = q.front();
    q.pop();
    rep(i, 0, 25) {
      if (tr[p][i]) {
        q.push(tr[p][i]);
        int fp = fail[tr[p][i]] = tr[fail[p]][i];
        deg[fp]++;
      } else {
        tr[p][i] = tr[fail[p]][i];
      }
    }
  }
}
void search(string& t) {
  int p = 0;
  for (char c : t) {
    p = tr[p][c - 'a'];
    cnt[p]++;
  }
}
int ans[N];
void toposort() {
  queue<int> q;
  rep(i, 1, tot) if (!deg[i]) q.push(i);
  while (q.size()) {
    int p = q.front();
    q.pop();
    for (int x : a[p]) ans[x] = cnt[p];
    cnt[fail[p]] += cnt[p];
    if (--deg[fail[p]] == 0) q.push(fail[p]);
  }
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  rep(i, 1, n) {
    string s;
    cin >> s;
    insert(s, i);
  }
  build_ac();
  string t;
  cin >> t;
  search(t);
  toposort();
  rep(i, 1, n) cout << ans[i] << endl;
  return 0;
}